<template>
    <div class="safework">
        <div class="content">
            <div class="c-top">
                <div class="c-list">
                    <div class="c-left">
                        项目名称
                    </div>
                    <div class="c-right">
                        <div class="c-select">{{dataList.ProjectName}}</div>
                    </div>
                </div>
                <div class="c-list">
                    <div class="c-left">
                        申请单位
                        <i class="iconfont icon-required"></i>
                    </div>
                    <div class="c-right">
                        <div class="c-select">{{dataList.DeptName}}</div>
                    </div>
                </div>
                <div class="c-list">
                    <div class="c-left">
                        作业区域
                        <i class="iconfont icon-required"></i>
                    </div>
                    <div class="c-right">
                        <div class="c-select">{{dataList.AreaName}}</div>
                    </div>
                </div>
                <div class="c-list">
                    <div class="c-left">
                        作业开始日期
                        <i class="iconfont icon-required"></i>
                    </div>
                    <div class="c-right">
                        <div class="c-select">{{dataList.StartDate|filterdata}}</div>
                    </div>
                </div>
                <div class="c-list">
                    <div class="c-left">
                        作业结束日期
                        <i class="iconfont icon-required"></i>
                    </div>
                    <div class="c-right">
                        <div class="c-select">{{dataList.EndDate|filterdata}}</div>
                    </div>
                </div>
                <div class="c-list">
                    <div class="c-left">
                        监护人
                        <i class="iconfont icon-required"></i>
                    </div>
                    <div class="c-right">
                        <div class="c-select">{{dataList.Guardian}}</div>
                    </div>
                </div>
                <div class="c-l-l">
                    <div class="c-left"
                         style="display:inline-block">
                        作业楼层
                        <i class="iconfont icon-required"></i>
                    </div>
                    <!-- <textarea readonly
                              v-model="dataList.Floor"
                              class="textarea"></textarea> -->
                    <p class="textarea">{{dataList.Floor}}</p>
                </div>
                <div class="c-list">
                    <div class="c-left">
                        作业类型
                        <i class="iconfont icon-required"></i>
                    </div>
                    <div class="c-right">
                        <div class="c-select">{{dataList.WorkTypes}}</div>
                    </div>
                </div>
                <div class="c-list">
                    <div class="c-left">
                        分部分项工程
                        <i class="iconfont icon-required"></i>
                    </div>
                    <div class="c-right">
                        <div class="c-select">{{dataList.PlanText}}</div>
                    </div>
                </div>
                <div class="c-list">
                    <div class="c-left">
                        防范措施
                        <i class="iconfont icon-required"></i>
                    </div>
                    <div class="c-right">
                        <div class="c-select">{{dataList.DefenceText}}</div>
                    </div>
                </div>
            </div>

            <div class="line"></div>
            <div class="form-section">
                <h3>审批信息</h3>
                <div v-for="(item,index) in dataList.ApproveInfo"
                     :key="index"
                     class="list-item">
                    <div class="form-item form-item-style2">
                        <div class="label-title">
                            <label>审批意见</label>
                        </div>
                        <div>
                            <p class="textarea">{{item.Remark}}</p>
                        </div>
                    </div>
                    <div class="form-item form-item-style1">
                        <div class="label-title">
                            <label>审批结论</label>
                        </div>
                        <div>
                            <p>{{item.ApproveResult}}</p>
                        </div>
                    </div>
                    <div class="line"></div>
                </div>
            </div>
            <!-- <div class="content-show">
                <div class="c-l-l">
                    <div>审批意见</div>
                    <textarea readonly
                              v-model="dataList.ApproveRemark"
                              class="textarea"></textarea>
                </div>
            </div> -->
            <div class="content-show"
                 v-if="syself||mStatus==2">
                <div class="c-l-l">
                    <div>监控意见</div>
                    <textarea v-if="mStatus==1"
                              maxlength="50"
                              v-model="jkdata.MonitoringRemark"
                              placeholder="请输入监控意见"
                              class="textarea"></textarea>
                    <!-- <textarea v-if="mStatus==2"
                              v-model="dataList.MonitoringRemark"
                              disabled
                              class="textarea"></textarea> -->
                    <p v-if="mStatus==2"
                       class="textarea">{{dataList.MonitoringRemark}}</p>
                </div>
            </div>
            <div class="showstyleBox">
                <div class="showstyle"
                     v-if="syself&&mStatus==1">
                    <div class="newqqq">
                        <div class="space-between">
                            <label>监控图片</label>
                        </div>
                        <span>当前共{{uploadLength}}张照片</span>
                    </div>
                    <div class="upload-wrap">
                        <upload @setFormData="setFormData"></upload>
                    </div>
                </div>

                <div class="showstyle"
                     v-if="mStatus==2">
                    <div class="newqqq">
                        <div class="space-between">
                            <label>监控图片</label>

                        </div>
                        <span>当前共{{dataList.MonitoringPath.length}}张照片</span>
                    </div>

                    <!-- <div class="imgshow">
                    <img :src="item"
                         :preview="'preview'"
                         v-for="(item,index) in dataList.MonitoringPath">
                </div> -->
                    <div class="upload-wrap">
                        <upload v-if="dataList.MonitoringPath&&dataList.MonitoringPath.length>0"
                                :imgList="dataList.MonitoringPath"></upload>
                        <strong v-else
                                class="no-img">暂无图片</strong>
                    </div>
                </div>
            </div>
            <div class="c-top"
                 v-if="syself&&mStatus==1">
                <div class="c-list">
                    <div class="c-left">
                        监控人员
                    </div>
                    <div class="c-right">
                        {{jkdata.MonitoringPeople}}
                    </div>
                </div>
            </div>
            <div class="c-top"
                 v-if="mStatus==2">
                <div class="c-list">
                    <div class="c-left">
                        监控人员
                    </div>
                    <div class="c-right">
                        {{jkdata.MonitoringPeople}}
                    </div>
                </div>
            </div>
            <div class="c-btn"
                 v-if="mStatus==1&&syself">
                <div class="c-submit"
                     @click="submitmessage">提交</div>

            </div>
        </div>
        <myMenu></myMenu>
    </div>
</template>

<script>

import myMenu from '@/commonComponents/menu'
import upload from '@/commonComponents/upload/index'
export default {
    name: 'App',
    directives: {
        // TransferDom
    },
    data () {
        return {
            options1: ['A单位'],
            options2: ['安全类'],
            active: 1,
            showflag: false,
            dataList: {
                MonitoringPath: []
            },
            jkdata: {
                id: '', //	String	否	起重吊装作业ID
                Monitoring: 'true', //	boolean	否	是否监控
                MonitoringPeople: '', //	String	否	监控人员
                MonitoringPath: [], //	String	否	监控图片
                MonitoringRemark: '', //	String	否	监控意见
                CheckResult: true
            },
            formData: '',
            images: [],
            uploadLength: 0,
            mStatus: '',
            syself: '',
            addflag: true
        }
    },
    components: {
        upload, myMenu
    },
    computed: {
    },
    watch: {
    },
    created () {
        this.mStatus = this.$route.query.mStatus
        this.userInfo = JSON.parse(localStorage.userInfo)
        this.userId = this.userInfo.userid
        this.tokenId = this.userInfo.tokenId
        this.projectId = this.userInfo.deptid
        this.jkdata.MonitoringPeople = this.userInfo.username
        this.jkdata.id = this.$route.query.id
        // this.syself = this.rolecheck()
        this.getdata()
    },
    methods: {
        rolecheck () {
            // index==1  验证是否是项目施工员  index==2  验证是否是设备管理员
            let arr = []
            let flag = false
            arr = this.userInfo.usermode.split(',')
            arr.forEach(
                (item, index) => {
                    if (item == '项目安全员') {
                        flag = true
                    }
                }
            )
            return flag
        },
        getdata () {
            let param = {
                'allowPaging': true,
                'business': 'GetSiteDangerJob',
                'data': {
                    'id': this.$route.query.id
                },
                'pageIndex': 0,
                'pageSize': 20,
                'tokenId': this.tokenId,
                'userId': this.userId
            }
            this.$axiosAjax.getConfigJson(
                param
            ).then(
                (res) => {
                    this.syself = res.data.data.CanEdit
                    this.dataList = res.data.data
                }
            )
        },
        submitmessage () {
            if (!this.addflag) {
                return false
            }
            this.addflag = false
            let param = {
                'allowPaging': true,
                'business': 'SiteDangerCheck',
                'data': this.jkdata,
                'pageIndex': 0,
                'pageSize': 20,
                'tokenId': this.tokenId,
                'userId': this.userId
            }
            this.$vux.loading.show({
                text: '正在提交中...'
            })
            this.$axiosAjax.getConfigJson(
                param, this.formData
            ).then(
                (res) => {
                    if (res.data.code == 0) {
                        // this.$router.push('/workrisk')
                        this.$router.go(-1)
                    } else {
                        this.addflag = true
                    }
                }
            ).catch(
                () => {
                    this.addflag = true
                }
            )
        },
        setFormData (formData, uploadLength, images) {
            this.formData = formData
            this.uploadLength = uploadLength
            this.images = images
        }

    },
    filters: {
        filterdata (val) {
            if (!val) {
                return false
            }
            return val.substring(0, 10)
        }
    }
}
</script>

<style scoped lang="less">
.safework {
    background-color: #ebeef3;
    height: 100%;
}
.content {
    background-color: #fff;
}
.c-top {
    background-color: #fff;
    padding-left: 20px;
}
.c-list {
    padding: 20px 20px 20px 0;
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid #efeff4;
}
.c-left {
    font-size: 14px;
    color: #666;
    position: relative;
}
.c-left > i {
    position: absolute;
    top: -5px;
    right: -18px;
}
.c-right {
    color: #999;
    font-size: 14px;
    // display:flex;
    align-items: center;
    width: 160px;
    text-align: right;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}
.c-select {
    margin-right: 6px;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    // width:200px;
    margin-right: 6px;
    text-align: right;
    font-size: 14px;
    color: #999;
}
.c-btn {
    height: 113px;
    padding-top: 32px;
}
.c-submit {
    width: 200px;
    height: 40px;
    line-height: 40px;
    text-align: center;
    font-size: 15px;
    color: #fff;
    border-radius: 20px;
    background-color: #2269ff;
    margin: 0 auto;
}
.content-show {
    padding-left: 20px;
    background-color: #fff;
}
.c-l-l {
    height: 95px;
    padding-top: 28px;
    padding-right: 20px;
    border-bottom: 1px solid #ebeef3;
    font-size: 13px;
}
.c-l-l > div {
    font-size: 14px;
    color: #666;
}
.textarea {
    width: 100%;
    border: 0;
    outline: none;
    margin-top: 10px;
    font-size: 14px;
    color: #999;
}
.newMsg {
    margin-top: 20px;
    padding-right: 20px;
    color: #999;
}
.c-l-ll {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid #ebeef3;
}
.rightselct {
    display: flex;
}
.tofirst {
    display: flex;
    align-items: center;
    width: 120px;
    height: 55px;
    text-align: center;
}
.selecti {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1px solid #999;
    margin-right: 10px;
}
.selecti.active {
    border: 3px solid #226afd;
}
.showstyleBox {
    background-color: #fff;
}
.showstyle {
    padding: 20px 20px 0 0;
    margin-left: 20px;
    font-size: 14px;
    border-bottom: 1px solid #ebeef3;
}
.newqqq {
    display: flex;
    justify-content: space-between;
}
.upload-wrap {
    border-bottom: 1px solid #ebeef3;
}
.imgshow {
    padding: 20px;
    background-color: #fff;
    display: flex;
    flex-wrap: wrap;
    padding-left: 0;
}
.imgshow > img {
    width: 60px;
    height: 60px;
    margin-right: 10px;
    margin-bottom: 10px;
}
.safework textarea[disabled='disabled'] {
    background-color: #fff;
}
.line {
    border-bottom: 10px solid #ebeef2;
}
</style>
